home *** CD-ROM | disk | FTP | other *** search
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Forecastfox.
- *
- * The Initial Developer of the Original Code is
- * Jon Stritar <jstritar@MIT.EDU>.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Jon Stritar <jstritar@MIT.EDU>
- * Richard Klein <richwklein@mchsi.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- const IPACK_CLASS_ID = Components.ID("{318412d0-0a0e-11da-8cd6-0800200c9a66}");
- const IPACK_CLASS_NAME = "Forecastfox Icon Pack Component";
- const IPACK_CONTRACT_ID = "@ensolis.com/forecastfox/icon-pack;1";
- const IINFO_CLASS_ID = Components.ID("{54b44420-11af-11da-8cd6-0800200c9a66}");
- const IINFO_CLASS_NAME = "Forecastfox Icon Information Component";
- const IINFO_CONTRACT_ID = "@ensolis.com/forecastfox/icon-info;1";
- const ffIDisk = Components.interfaces.ffIDisk;
-
- function ffIconPack() {};
-
- ffIconPack.prototype = {
- _id: "default",
- _jar: "default.jar",
- _name: "AccuWeather.com® Classic Icons",
- _website: "http://www.accuweather.com/",
- _author: "AccuWeather.com®",
- _version: "1.0",
- _smallHeight: 20,
- _smallWidth: 32,
- _largeHeight: 40,
- _largeWidth: 64,
- _target: "1.0",
- _manager: null,
- _exemptions: null,
-
- get id() { return this._id; },
- get jar() { return this._jar; },
- get name() { return this._name; },
- get website() { return this._website; },
- get author() { return this._author; },
- get version() { return this._version; },
- get target() { return this._target },
-
- init: function( aId, aJar, aName, aWebsite, aAuthor, aVersion, aTarget, aSmallHeight,
- aSmallWidth, aLargeHeight, aLargeWidth, aCount, aExemptions)
- {
- this._manager = Components.classes["@ensolis.com/forecastfox/manager;1"].getService(Components.interfaces.ffIManager);
- this._id = aId;
- this._jar = aJar;
- this._name = aName;
- this._website = aWebsite;
- this._author = aAuthor;
- this._version = aVersion;
- this._smallHeight = aSmallHeight;
- this._smallWidth = aSmallWidth;
- this._largeHeight = aLargeHeight;
- this._largeWidth = aLargeWidth;
- this._target = aTarget;
-
- // prepare the exemptions
- this._exemptions = {};
- this._exemptions['large'] = {};
- this._exemptions['small'] = {};
-
- // process the exemptions (we need to create new ones so they have valid URIs)
- for (var x = 0; x < aCount; x++) {
- var exemption = aExemptions[x];
- var iconInfo = Components.classes["@ensolis.com/forecastfox/icon-info;1"].createInstance(Components.interfaces.ffIIconInfo);
- iconInfo.init(this._getURIOf(exemption.index, exemption.large), exemption.width, exemption.height, exemption.large, exemption.index);
- this._exemptions[this._getSize(exemption.large)][exemption.index] = iconInfo;
- };
- },
-
- destroy: function()
- {
- this._manager = null;
- this._id = null;
- this._jar = null;
- this._name = null;
- this._website = null;
- this._author = null;
- this._version = null;
- this._target = null;
- this._smallHeight = null;
- this._smallWidth = null;
- this._largeHeight = null;
- this._largeWidth = null;
- this._exemptions = null;
- },
-
- getIcon: function( aIndex, aLarge )
- {
- var iconInfo = this._exemptions[this._getSize(aLarge)][aIndex];
-
- // return the exemption info if it is an exemption...
- if (iconInfo) return iconInfo;
-
- // otherwise create an icon to return
- iconInfo = Components.classes["@ensolis.com/forecastfox/icon-info;1"].createInstance(Components.interfaces.ffIIconInfo);
-
- var width, height;
- if (aLarge) {
- width = this._largeWidth;
- height = this._largeHeight;
- } else {
- width = this._smallWidth;
- height = this._smallHeight;
- };
-
- iconInfo.init(this._getURIOf(aIndex, aLarge), width, height, aLarge, aIndex);
-
- return iconInfo;
- },
-
- getPreview: function()
- {
- //open file in zip reader
- var file = this._manager.disk.get(this._jar, ffIDisk.TYPE_ICONS);
- var reader = Components.classes["@mozilla.org/libjar/zip-reader;1"].createInstance(Components.interfaces.nsIZipReader);
- reader.init(file);
- reader.open();
-
- //try to get the preview entry
- try {
- var entry = reader.getEntry("preview.png");
- reader.close();
- } catch(e) {
- return "";
- };
-
- //return url to preview
- file = this._manager.disk.get(this._jar +"!", ffIDisk.TYPE_ICONS);
- file.append("preview.png");
- return "jar:" + this._manager.disk.getFileURI(file);
- },
-
- _getURIOf: function( aIndex, aLarge )
- {
- // get the nsIFile of the image
- var file = this._manager.disk.get(this._jar+"!", ffIDisk.TYPE_ICONS);
- file.append(aLarge?"large":"small");
- file.append(aIndex + ".png");
-
- // then convert it to a url
- return "jar:" + this._manager.disk.getFileURI(file);
- },
-
- _getSize: function( aLarge )
- {
- return aLarge ? "large" : "small";
- },
-
- ///////////////////////////
- // nsIClassInfo
- getInterfaces: function(aCount)
- {
- var ifaces = new Array();
- ifaces.push(Components.interfaces.ffIIconPack);
- ifaces.push(Components.interfaces.nsIClassInfo);
- ifaces.push(Components.interfaces.nsISupports);
- aCount.value = ifaces.length;
- return ifaces;
- },
-
- getHelperForLanguage: function(aLanguage) { return null; },
- get contractID() { return IPACK_CONTRACT_ID; },
- get classID() { return IPACK_CLASS_ID; },
- get classDescription() { return IPACK_CLASS_NAME; },
- get implementationLanguage() { return Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT; },
- get flags() { return Components.interfaces.nsIClassInfo.THREADSAFE; },
-
- ///////////////////////////
- // nsISupports
- QueryInterface: function (aIID)
- {
- if (!aIID.equals(Components.interfaces.ffIIconPack) &&
- !aIID.equals(Components.interfaces.nsIClassInfo) &&
- !aIID.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- };
-
- function ffIconInfo() {};
-
- ffIconInfo.prototype = {
- _uri: null,
- _width: null,
- _height: null,
- _large: null,
- _index: null,
-
- get uri() { return this._uri; },
- get width() { return this._width; },
- get height() { return this._height; },
- get large() { return this._large; },
- get index() { return this._index; },
-
- init: function( aUri, aWidth, aHeight, aLarge, aIndex )
- {
- this._uri = aUri;
- this._width = aWidth;
- this._height = aHeight;
- this._large = aLarge;
- this._index = aIndex;
- },
-
- destroy: function()
- {
- this._uri = null;
- this._width = null;
- this._height = null;
- this._large = null;
- this._index = null;
- },
-
- ///////////////////////////
- // nsIClassInfo
- getInterfaces: function(aCount)
- {
- var ifaces = new Array();
- ifaces.push(Components.interfaces.ffIIconInfo);
- ifaces.push(Components.interfaces.nsIClassInfo);
- ifaces.push(Components.interfaces.nsISupports);
- aCount.value = ifaces.length;
- return ifaces;
- },
-
- getHelperForLanguage: function(aLanguage) { return null; },
- get contractID() { return IINFO_CONTRACT_ID; },
- get classID() { return IINFO_CLASS_ID; },
- get classDescription() { return IINFO_CLASS_NAME; },
- get implementationLanguage() { return Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT; },
- get flags() { return Components.interfaces.nsIClassInfo.THREADSAFE; },
-
- ///////////////////////////
- // nsISupports
- QueryInterface: function (aIID)
- {
- if (!aIID.equals(Components.interfaces.ffIIconInfo) &&
- !aIID.equals(Components.interfaces.nsIClassInfo) &&
- !aIID.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- };
-
- /******************************************************************************
- * XPCOM Functions for construction and registration
- ******************************************************************************/
- var gModule = {
- _firstTime: true,
-
- _objects: {
- iconPack: {
- CID: IPACK_CLASS_ID,
- contractID: IPACK_CONTRACT_ID,
- className: IPACK_CLASS_NAME,
- factory: {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new ffIconPack()).QueryInterface(aIID);
- }
- }
- },
-
- iconInfo: {
- CID: IINFO_CLASS_ID,
- contractID: IINFO_CONTRACT_ID,
- className: IINFO_CLASS_NAME,
- factory: {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new ffIconInfo()).QueryInterface(aIID);
- }
- }
- }
- },
-
- registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
- {
- if (this._firstTime) {
- this._firstTime = false;
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- };
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- for (var key in this._objects) {
- var obj = this._objects[key];
- aCompMgr.registerFactoryLocation(obj.CID, obj.className, obj.contractID,
- aFileSpec, aLocation, aType);
- };
- },
-
- unregisterSelf: function(aCompMgr, aLocation, aType)
- {
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- for (var key in this._objects) {
- var obj = this._objects[key];
- aCompMgr.unregisterFactoryLocation(obj.CID, aLocation);
- };
- },
-
- getClassObject: function(aCompMgr, aCID, aIID)
- {
- if (!aIID.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- for (var key in this._objects) {
- if (aCID.equals(this._objects[key].CID))
- return this._objects[key].factory;
- };
-
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
- canUnload: function(aCompMgr) { return true; }
- };
-
- function NSGetModule(aCompMgr, aFileSpec) { return gModule; }